from django.db import models
from .chapter import Chapter
from .base_model import BaseModel

class KnowledgePoint(BaseModel):
    chapter = models.ForeignKey(Chapter, on_delete=models.CASCADE, related_name='knowledge_points', verbose_name='章节')
    name = models.CharField(max_length=100, verbose_name='知识点名称')
    description = models.TextField(blank=True, null=True, verbose_name='知识点描述')
    order = models.PositiveIntegerField(default=0, verbose_name='排序')

    class Meta:
        verbose_name = '知识点'
        verbose_name_plural = '知识点'
        ordering = ['order']
        unique_together = ['chapter', 'name']

    def __str__(self):
        return f'{self.chapter} - {self.name}'